package com.lagou.bak;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.util.Collector;
import org.apache.flink.util.OutputTag;

public class OutPutTagTest {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<MyBean> data = env.fromElements(new MyBean("1"),new MyBean("2"));


        OutputTag<MyBean> outputTag = new OutputTag<MyBean>("delay-side-output"){};



        SingleOutputStreamOperator<String> processed = data.process(new ProcessFunction<MyBean, String>() {
            @Override
            public void processElement(MyBean value, Context ctx, Collector<String> out) throws Exception {
                if (Long.valueOf(value.getValue()) < 2) {
                    out.collect(value.getValue());
                } else {
                    ctx.output(outputTag,new MyBean("测流" + value));
                }
            }
        });
        processed.print();
        processed.getSideOutput(outputTag).print();
        env.execute();
    }
}

class MyBean{
    private String value;

    public MyBean(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return "MyBean{" +
                "value='" + value + '\'' +
                '}';
    }
}
